package com.gmail.liulijuan.class2;

public class Sorter {

	static int[] c;

	public void setC(int[] a) {
		c = new int[a.length];
		for (int i = 0; i < c.length; i++) {
			c[i] = a[i];
		}
	}

	public int[] sortChaRu(int t) {
		int b;
		if (t == 0) {
			for (int i = 0; i < c.length; i++) {
				for (int j = 0; j < i; j++) {
					if (c[i] > c[j]) {
						b = c[i];
						c[i] = c[j];
						c[j] = b;
					}
				}
			}
		} else {
			for (int m = 0; m < c.length; m++) {
				for (int n = 0; n < m; n++) {
					if (c[m] < c[n]) {
						b = c[m];
						c[m] = c[n];
						c[n] = b;
					}
				}
			}
		}
		return c;
	}

	public int[] sortMaoPao(int t) {
		int b;
		for (int i = 1; i < c.length; i++) {
			for (int j = 0; j < c.length - i; j++) {
				if (c[j + 1] > c[j]) {
					b = c[j];
					c[j] = c[j + 1];
					c[j + 1] = b;
				}
			}
		}
		if (t > 0) {
			return reverse(c);
		}
		return c;
	}

	public int[] sortShunXu(int t) {
		int b;
		for (int i = 0; i < c.length; i++) {
			for (int j = i; j < c.length; j++) {
				if (c[i] < c[j]) {
					b = c[i];
					c[i] = c[j];
					c[j] = b;
				}
			}
		}
		if (t > 0) {
			return reverse(c);
		}
		return c;
	}

	private int[] reverse(int[] a) {
		int[] b = new int[a.length];
		for (int i = 0; i < b.length; i++) {
			b[i] = a[a.length - i - 1];
		}
		return b;
	}

	Sorter() {

	}

}
